package labox.innovation.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import labox.innovation.gameserver.util.StringUtil;
import labox.innovation.util.L2Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CharacterConfig {

    private static final Logger _log = LoggerFactory.getLogger(CharacterConfig.class.getName());
    private static final String CHARACTER_CONFIG_FILE = "./config/character.properties";

    public static String LEARN_SKILL_LVL;
    // --------------------------------------------------
    // L2J Variable Definitions
    // --------------------------------------------------
    /**
     * 用户的连接权限值127~255，大的权限将可以执行管理员命令
     */
    public static int MASTERACCESS_LEVEL;

    /**
     * 相应权限的名字颜色
     */
    public static int MASTERACCESS_NAME_COLOR;

    /**
     * 相应权限的头衔的颜色
     */
    public static int MASTERACCESS_TITLE_COLOR;

    /**
     * 重生时HP的回复百分比
     */
    public static float RESPAWN_RESTORE_HP;

    /**
     * 重生时MP的回复百分比
     */
    public static float RESPAWN_RESTORE_MP;

    /**
     * 原地复活的花费
     */
    public static int RESPAWN_COST;

    /**
     * 角色所能获得的所有buff
     */
    public static byte BUFFS_MAX_AMOUNT;

    /**
     * 是否允许多等级相同的效果替换
     */
    public static boolean EFFECT_CANCELING;

    /**
     * 是否允许魔法伤害有失败的情况
     */
    public static boolean ALT_GAME_MAGICFAILURES;

    /**
     * 是否保存身上的buff/debuff状态
     */
    public static boolean STORE_SKILL_COOLTIME;

    /**
     * 是否允许NPC修改职业，而不需要事件的发生
     */
    public static boolean ALLOW_CLASS_MASTERS;

    /**
     * 是否允许NPC修改职业，而无视任何限制
     */
    public static boolean ALLOW_ENTIRE_TREE;

    /**
     * 所有的技能都能学习
     */
    public static boolean ALT_GAME_SKILL_LEARN;

    /**
     * 角色最大的移动速度
     */
    public static int MAX_RUN_SPEED;

    /**
     * 角色最大的暴击率
     */
    public static int MAX_CRIT_RATE;

    /**
     * 角色暴击伤害系数
     */
    public static float CRIT_DMG_RATE;

    /**
     * 角色最大物理攻击速度
     */
    public static int MAX_PATK_SPEED;

    /**
     * 角色最大魔法攻击速度
     */
    public static int MAX_MATK_SPEED;

    /**
     * 私人商店贩卖的最大槽位
     */
    public static int MAX_PVTSTORESELL_SLOTS_OTHER;

    /**
     * 私人商店购买的最大槽位
     */
    public static int MAX_PVTSTOREBUY_SLOTS_OTHER;

    /**
     * 玩家背包的最大空间
     */
    public static int INVENTORY_MAXIMUM;

    /**
     * GM背包的最大空间
     */
    public static int INVENTORY_MAXIMUM_GM;

    /**
     * 玩家仓库的最大空间
     */
    public static int WAREHOUSE_SLOTS_NO_DWARF;

    /**
     * 帮会的仓库的最大空间
     */
    public static int WAREHOUSE_SLOTS_CLAN;

    /**
     * 货仓空间
     */
    public static int FREIGHT_SLOTS;

    /**
     * 是否在安全区能够PK红名玩家
     */
    public static boolean ALT_GAME_KARMA_PLAYER_CAN_BE_KILLED_IN_PEACEZONE;

    /**
     * 是否红名玩家能够使用商店
     */
    public static boolean ALT_GAME_KARMA_PLAYER_CAN_SHOP;

    /**
     * 是否红名玩家可以交易
     */
    public static boolean ALT_GAME_KARMA_PLAYER_CAN_TRADE;

    /**
     * 是否红名玩家可以使用仓库
     */
    public static boolean ALT_GAME_KARMA_PLAYER_CAN_USE_WAREHOUSE;

    /**
     * 新手保护等级
     */
    public static int PK_LEVEL_MIN;

    public static int ALT_CLAN_JOIN_DAYS;

    public static int ALT_CLAN_CREATE_DAYS;

    public static int ALT_CLAN_DISSOLVE_DAYS;

    public static int ALT_ALLY_JOIN_DAYS_WHEN_LEAVED;

    public static int ALT_ALLY_JOIN_DAYS_WHEN_DISMISSED;

    public static int ALT_ACCEPT_CLAN_DAYS_WHEN_DISMISSED;

    public static int ALT_CREATE_ALLY_DAYS_WHEN_DISSOLVED;

    public static int ALT_MAX_NUM_OF_CLANS_IN_ALLY;

    public static int ALT_CLAN_MEMBERS_FOR_WAR;

    public static boolean ALT_MEMBERS_CAN_WITHDRAW_FROM_CLANWH;

    public static boolean REMOVE_CASTLE_CIRCLETS;

    public static int ALT_PARTY_RANGE;

    public static int ALT_PARTY_RANGE2;

    /**
     * 初始配置给角色的游戏币
     */
    public static int STARTING_ADENA;

    public static byte STARTING_LEVEL;

    public static boolean AUTO_LOOT;

    public static boolean AUTO_LOOT_RAIDS;

    public static int UNSTUCK_INTERVAL;

    /**
     * 玩家出生保护
     */
    public static int PLAYER_SPAWN_PROTECTION;

    public static boolean RESPAWN_RANDOM_ENABLED;

    public static int RESPAWN_RANDOM_MAX_OFFSET;

    public static boolean RESTORE_PLAYER_INSTANCE;

    public static boolean ALLOW_SUMMON_TO_INSTANCE;

    public static boolean PETITIONING_ALLOWED;

    public static int MAX_PETITIONS_PER_PLAYER;

    public static int MAX_PETITIONS_PENDING;

    public static boolean ALT_GAME_FREIGHTS;

    public static int ALT_GAME_FREIGHT_PRICE;

    public static boolean ALT_GAME_FREE_TELEPORT;

    public static boolean ALT_RECOMMEND;

    /**
     * 角色被标记删除后，几天后被真正的删除
     */
    public static int DELETE_DAYS;

    /**
     * 系统经验系数
     */
    public static float ALT_GAME_EXPONENT_XP;

    public static String PARTY_XP_CUTOFF_METHOD;

    public static double PARTY_XP_CUTOFF_PERCENT;

    public static int PARTY_XP_CUTOFF_LEVEL;

    public static int MAX_ITEM_IN_PACKET;

    /**
     * 武器强化的成功率
     */
    public static int ENCHANT_CHANCE_WEAPON;

    /**
     * 装备强化的成功率
     */
    public static int ENCHANT_CHANCE_ARMOR;

    /**
     * 武器最大的强化次数
     */
    public static int ENCHANT_MAX_WEAPON;

    /**
     * 装备最大的强化次数
     */
    public static int ENCHANT_MAX_ARMOR;

    /**
     * 好友上限
     */
    public static int FRIENDSLIMIT;

    /**
     * 好友消息上限
     */
    public static int FRIENDSNEWSLIMIT;

    /**
     * 离线保存角色队伍时间
     */
    public static int LOGOUTSPACETIME;

    /**
     * 检测离线用户时间间隔
     */
    public static int LOGOUTCHECKTIME;

    public static int LEVELUP_UNASSIGNPOINT;

    /**
     * 元宝兑换成银文比率
     */
    public static int INGOT2SILVERRATE;

    /**
     * NPC修理买卖善恶值惩罚参数基数
     */
    public static int KARMABASE;

    /**
     * 红名善恶值大小设置
     */
    public static int KARMAREDSSET;

    /**
     * 角色昵称过滤器
     */
    public static String[] NICKNAMEFILTER;

    public static void load() {
        _log.info("Loading character Configuration Files...", Config.SERVER_ID);
        InputStream is = null;
        try {

            L2Properties Character = new L2Properties();
            is = new FileInputStream(new File(CHARACTER_CONFIG_FILE));
            Character.load(is, "UTF-8");

            LEARN_SKILL_LVL = Character.getProperty("LearnSkillLevel", null);
            MASTERACCESS_LEVEL = Integer.parseInt(Character.getProperty("MasterAccessLevel", "127"));
            MASTERACCESS_NAME_COLOR = Integer.decode(StringUtil.concat("0x", Character.getProperty("MasterNameColor", "00FF00")));
            MASTERACCESS_TITLE_COLOR = Integer.decode(StringUtil.concat("0x", Character.getProperty("MasterTitleColor", "00FF00")));
            RESPAWN_RESTORE_HP = Float.parseFloat(Character.getProperty("RespawnRestoreHP", "70")) / 100;
            RESPAWN_RESTORE_MP = Float.parseFloat(Character.getProperty("RespawnRestoreMP", "70")) / 100;
            RESPAWN_COST = Integer.parseInt(Character.getProperty("RespawnCost", "1"));

            BUFFS_MAX_AMOUNT = Byte.parseByte(Character.getProperty("maxbuffamount", "20"));

            EFFECT_CANCELING = Boolean.parseBoolean(Character.getProperty("CancelLesserEffect", "True"));

            ALT_GAME_MAGICFAILURES = Boolean.parseBoolean(Character.getProperty("MagicFailures", "true"));

            STORE_SKILL_COOLTIME = Boolean.parseBoolean(Character.getProperty("StoreSkillCooltime", "true"));

            ALLOW_CLASS_MASTERS = Boolean.parseBoolean(Character.getProperty("AllowClassMasters", "False"));
            ALLOW_ENTIRE_TREE = Boolean.parseBoolean(Character.getProperty("AllowEntireTree", "False"));

            ALT_GAME_SKILL_LEARN = Boolean.parseBoolean(Character.getProperty("AltGameSkillLearn", "false"));

            MAX_RUN_SPEED = Integer.parseInt(Character.getProperty("MaxRunSpeed", "8"));

            MAX_CRIT_RATE = Integer.parseInt(Character.getProperty("MaxCritRate", "100"));
            CRIT_DMG_RATE = Float.parseFloat(Character.getProperty("CritDmgRate", "1.5"));

            MAX_PATK_SPEED = Integer.parseInt(Character.getProperty("MaxPAtkSpeed", "1500"));
            MAX_MATK_SPEED = Integer.parseInt(Character.getProperty("MaxMAtkSpeed", "1999"));

            MAX_PVTSTORESELL_SLOTS_OTHER = Integer.parseInt(Character.getProperty("MaxPvtStoreSellSlotsOther", "3"));
            MAX_PVTSTOREBUY_SLOTS_OTHER = Integer.parseInt(Character.getProperty("MaxPvtStoreBuySlotsOther", "4"));

            INVENTORY_MAXIMUM = Integer.parseInt(Character.getProperty("MaximumSlotsForNoDwarf", "80"));

            INVENTORY_MAXIMUM_GM = Integer.parseInt(Character.getProperty("MaximumSlotsForGMPlayer", "250"));
            MAX_ITEM_IN_PACKET = INVENTORY_MAXIMUM_GM;

            WAREHOUSE_SLOTS_NO_DWARF = Integer.parseInt(Character.getProperty("MaximumWarehouseSlotsForNoDwarf", "100"));
            WAREHOUSE_SLOTS_CLAN = Integer.parseInt(Character.getProperty("MaximumWarehouseSlotsForClan", "150"));
            FREIGHT_SLOTS = Integer.parseInt(Character.getProperty("MaximumFreightSlots", "20"));

            ENCHANT_CHANCE_WEAPON = Integer.parseInt(Character.getProperty("EnchantChanceWeapon", "66"));

            ENCHANT_CHANCE_ARMOR = Integer.parseInt(Character.getProperty("EnchantChanceArmor", "66"));

            ENCHANT_MAX_WEAPON = Integer.parseInt(Character.getProperty("EnchantMaxWeapon", "0"));
            ENCHANT_MAX_ARMOR = Integer.parseInt(Character.getProperty("EnchantMaxArmor", "0"));

            ALT_GAME_KARMA_PLAYER_CAN_BE_KILLED_IN_PEACEZONE = Boolean.parseBoolean(Character.getProperty("AltKarmaPlayerCanBeKilledInPeaceZone", "false"));
            ALT_GAME_KARMA_PLAYER_CAN_SHOP = Boolean.parseBoolean(Character.getProperty("AltKarmaPlayerCanShop", "true"));
            ALT_GAME_KARMA_PLAYER_CAN_TRADE = Boolean.parseBoolean(Character.getProperty("AltKarmaPlayerCanTrade", "true"));
            ALT_GAME_KARMA_PLAYER_CAN_USE_WAREHOUSE = Boolean.parseBoolean(Character.getProperty("AltKarmaPlayerCanUseWareHouse", "true"));

            ALT_CLAN_JOIN_DAYS = Integer.parseInt(Character.getProperty("DaysBeforeJoinAClan", "1"));
            ALT_CLAN_CREATE_DAYS = Integer.parseInt(Character.getProperty("DaysBeforeCreateAClan", "10"));
            ALT_CLAN_DISSOLVE_DAYS = Integer.parseInt(Character.getProperty("DaysToPassToDissolveAClan", "7"));
            ALT_ALLY_JOIN_DAYS_WHEN_LEAVED = Integer.parseInt(Character.getProperty("DaysBeforeJoinAllyWhenLeaved", "1"));
            ALT_ALLY_JOIN_DAYS_WHEN_DISMISSED = Integer.parseInt(Character.getProperty("DaysBeforeJoinAllyWhenDismissed", "1"));
            ALT_ACCEPT_CLAN_DAYS_WHEN_DISMISSED = Integer.parseInt(Character.getProperty("DaysBeforeAcceptNewClanWhenDismissed", "1"));
            ALT_CREATE_ALLY_DAYS_WHEN_DISSOLVED = Integer.parseInt(Character.getProperty("DaysBeforeCreateNewAllyWhenDissolved", "1"));
            ALT_MAX_NUM_OF_CLANS_IN_ALLY = Integer.parseInt(Character.getProperty("AltMaxNumOfClansInAlly", "3"));
            ALT_CLAN_MEMBERS_FOR_WAR = Integer.parseInt(Character.getProperty("AltClanMembersForWar", "15"));
            ALT_MEMBERS_CAN_WITHDRAW_FROM_CLANWH = Boolean.parseBoolean(Character.getProperty("AltMembersCanWithdrawFromClanWH", "false"));
            REMOVE_CASTLE_CIRCLETS = Boolean.parseBoolean(Character.getProperty("RemoveCastleCirclets", "true"));

            ALT_PARTY_RANGE = Integer.parseInt(Character.getProperty("AltPartyRange", "1600"));
            ALT_PARTY_RANGE2 = Integer.parseInt(Character.getProperty("AltPartyRange2", "1400"));
            STARTING_ADENA = Integer.parseInt(Character.getProperty("StartingAdena", "0"));
            STARTING_LEVEL = Byte.parseByte(Character.getProperty("StartingLevel", "1"));

            AUTO_LOOT = Boolean.parseBoolean(Character.getProperty("AutoLoot", "false"));
            AUTO_LOOT_RAIDS = Boolean.parseBoolean(Character.getProperty("AutoLootRaids", "false"));
            UNSTUCK_INTERVAL = Integer.parseInt(Character.getProperty("UnstuckInterval", "300"));

            PLAYER_SPAWN_PROTECTION = Integer.parseInt(Character.getProperty("PlayerSpawnProtection", "0"));
            RESPAWN_RANDOM_ENABLED = Boolean.parseBoolean(Character.getProperty("RespawnRandomInTown", "True"));
            RESPAWN_RANDOM_MAX_OFFSET = Integer.parseInt(Character.getProperty("RespawnRandomMaxOffset", "50"));
            RESTORE_PLAYER_INSTANCE = Boolean.parseBoolean(Character.getProperty("RestorePlayerInstance", "False"));
            ALLOW_SUMMON_TO_INSTANCE = Boolean.parseBoolean(Character.getProperty("AllowSummonToInstance", "True"));
            PETITIONING_ALLOWED = Boolean.parseBoolean(Character.getProperty("PetitioningAllowed", "True"));
            MAX_PETITIONS_PER_PLAYER = Integer.parseInt(Character.getProperty("MaxPetitionsPerPlayer", "5"));
            MAX_PETITIONS_PENDING = Integer.parseInt(Character.getProperty("MaxPetitionsPending", "25"));
            ALT_GAME_FREIGHTS = Boolean.parseBoolean(Character.getProperty("AltGameFreights", "true"));
            ALT_GAME_FREIGHT_PRICE = Integer.parseInt(Character.getProperty("AltGameFreightPrice", "1000"));
            ALT_GAME_FREE_TELEPORT = Boolean.parseBoolean(Character.getProperty("AltFreeTeleporting", "False"));
            ALT_RECOMMEND = Boolean.parseBoolean(Character.getProperty("AltRecommend", "False"));
            DELETE_DAYS = Integer.parseInt(Character.getProperty("DeleteCharAfterDays", "7"));

            ALT_GAME_EXPONENT_XP = Float.parseFloat(Character.getProperty("AltGameExponentXp", "1."));

            PARTY_XP_CUTOFF_METHOD = Character.getProperty("PartyXpCutoffMethod", "auto");
            PARTY_XP_CUTOFF_PERCENT = Double.parseDouble(Character.getProperty("PartyXpCutoffPercent", "3."));
            PARTY_XP_CUTOFF_LEVEL = Integer.parseInt(Character.getProperty("PartyXpCutoffLevel", "30"));
            FRIENDSLIMIT = Integer.parseInt(Character.getProperty("FriendsLimit", "50"));
            FRIENDSNEWSLIMIT = Integer.parseInt(Character.getProperty("FriendsNewsLimit", "50"));
            LOGOUTSPACETIME = Integer.parseInt(Character.getProperty("LogOutSpaceTime", "600000"));
            LOGOUTCHECKTIME = Integer.parseInt(Character.getProperty("LogOutCheckTime", "600000"));
            PK_LEVEL_MIN = Integer.parseInt(Character.getProperty("pk_level_min", "20"));
            LEVELUP_UNASSIGNPOINT = Integer.parseInt(Character.getProperty("LevelUpUnassignPoint", "2"));
            INGOT2SILVERRATE = Integer.parseInt(Character.getProperty("IngotToSilverRate", "1"));
            KARMABASE = Integer.parseInt(Character.getProperty("KarmaBase", "250"));
            KARMAREDSSET = Integer.parseInt(Character.getProperty("KarmaRedsSet", "50"));
            NICKNAMEFILTER = Character.getProperty("NickNameFilter", "").split(",");

        } catch (Exception e) {
            _log.error("Failed to Load " + CHARACTER_CONFIG_FILE + " File.", e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                _log.error("InputStream close occured IOException");
            }
        }
    }
}
